package org.little.v5;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.little.context.ApplicationContext;
import org.little.context.support.ClassPathXmlApplicationContext;
import org.little.service.v5.PetStoreService;
import org.little.util.MessageTracker;

import java.util.List;

/**
 * @author Tinyspot
 * @date 2022-05-28 21:19
 */
public class ApplicationContextTest5 {

    @Before
    public void before() {
        MessageTracker.clearMessage();
    }

    @Test
    public void testPlaceOrder() {
        ApplicationContext context = new ClassPathXmlApplicationContext("little-v5.xml");
        PetStoreService petStoreService = (PetStoreService) context.getBean("petStore");

        Assert.assertNotNull(petStoreService.getAccountDao());
        Assert.assertNotNull(petStoreService.getItemDao());

        petStoreService.placeOrder();
        List<String> messages = MessageTracker.getMessages();
        Assert.assertEquals(3, messages.size());
        Assert.assertEquals("start tx", messages.get(0));
        Assert.assertEquals("place order", messages.get(1));
        Assert.assertEquals("commit tx", messages.get(2));
    }
}
